#include "expinstrumentcalframe.h"
#include "ui_expinstrumentcalframe.h"
#include "delegate.h"

ExpInstrumentCalFrame::ExpInstrumentCalFrame(QWidget *parent,Experiment* pExperiment) :
    QFrame(parent),
    ui(new Ui::ExpInstrumentCalFrame)
{
    ui->setupUi(this);
    this->pExperiment=pExperiment;

    SpinBoxDelegate *pSpinBoxDelegate=new SpinBoxDelegate(this);
    ui->tableWidget_Mass->setItemDelegateForColumn(2,pSpinBoxDelegate);
    DoubleSpinBoxDelegate *pDoubleSpinBoxDelegate=new DoubleSpinBoxDelegate(this);
    ui->tableWidget_Mass->setItemDelegateForColumn(3,pDoubleSpinBoxDelegate);
    LineEditDelegate *pLineEditDelegate=new LineEditDelegate(this,0);
    ui->tableWidget_Mass->setItemDelegateForColumn(4,pLineEditDelegate);
    pLineEditDelegate=new LineEditDelegate(this,0);
    ui->tableWidget_Mass->setItemDelegateForColumn(5,pLineEditDelegate);
    pLineEditDelegate=new LineEditDelegate(this,0);
    ui->tableWidget_Mass->setItemDelegateForColumn(6,pLineEditDelegate);

    LoadData();
}

ExpInstrumentCalFrame::~ExpInstrumentCalFrame()
{
    delete ui;
}

void ExpInstrumentCalFrame::LoadData()
{
    CalRatio calRatioStandard=pExperiment->GetMassCalStandard();
    int row,column;
    row=0;
    column=0;
    ui->tableWidget_Mass->setRowCount(2);
    QAbstractItemModel *pModel=ui->tableWidget_Mass->model();
    pModel->setData(pModel->index(row,column++),QVariant(tr("标准")),Qt::DisplayRole);//calRatioStandard.name
    pModel->setData(pModel->index(row,column++),QVariant(calRatioStandard.dateTime),Qt::DisplayRole);
    pModel->setData(pModel->index(row,column++),QVariant(calRatioStandard.ratios.at(4)),Qt::DisplayRole);
    pModel->setData(pModel->index(row,column++),QVariant(calRatioStandard.ratios.at(3)),Qt::DisplayRole);
    pModel->setData(pModel->index(row,column++),QVariant(calRatioStandard.ratios.at(2)),Qt::DisplayRole);
    pModel->setData(pModel->index(row,column++),QVariant(calRatioStandard.ratios.at(1)),Qt::DisplayRole);
    pModel->setData(pModel->index(row,column++),QVariant(calRatioStandard.ratios.at(0)),Qt::DisplayRole);
    CalRatio calRatioHigh=pExperiment->GetMassCalHigh();
    row=1;
    column=0;
    pModel->setData(pModel->index(row,column++),QVariant(tr("高标")),Qt::DisplayRole);//calRatioHigh.name
    pModel->setData(pModel->index(row,column++),QVariant(calRatioHigh.dateTime),Qt::DisplayRole);
    pModel->setData(pModel->index(row,column++),QVariant(calRatioHigh.ratios.at(4)),Qt::DisplayRole);
    pModel->setData(pModel->index(row,column++),QVariant(calRatioHigh.ratios.at(3)),Qt::DisplayRole);
    pModel->setData(pModel->index(row,column++),QVariant(calRatioHigh.ratios.at(2)),Qt::DisplayRole);
    pModel->setData(pModel->index(row,column++),QVariant(calRatioHigh.ratios.at(1)),Qt::DisplayRole);
    pModel->setData(pModel->index(row,column++),QVariant(calRatioHigh.ratios.at(0)),Qt::DisplayRole);

    CalRatio crossRatio=pExperiment->GetCrossCal();
    row=0;
    column=0;
    ui->tableWidget_Cross->setRowCount(1);
    pModel=ui->tableWidget_Cross->model();
    pModel->setData(pModel->index(row,column++),QVariant(crossRatio.name),Qt::DisplayRole);
    pModel->setData(pModel->index(row,column++),QVariant(crossRatio.dateTime),Qt::DisplayRole);
    pModel->setData(pModel->index(row,column++),QVariant(crossRatio.ratios.at(4)),Qt::DisplayRole);
    pModel->setData(pModel->index(row,column++),QVariant(crossRatio.ratios.at(3)),Qt::DisplayRole);
    pModel->setData(pModel->index(row,column++),QVariant(crossRatio.ratios.at(2)),Qt::DisplayRole);
    pModel->setData(pModel->index(row,column++),QVariant(crossRatio.ratios.at(1)),Qt::DisplayRole);
    pModel->setData(pModel->index(row,column++),QVariant(crossRatio.ratios.at(0)),Qt::DisplayRole);
}
